﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class Controls_Tour_ctrTourDetail : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    private int nDefaultLang = Support.GetDefaultLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetLangLable();
            LoadData();
        }
    }
    private int GetCountryID()
    {
        int nCountry = ConvertData.ConvertToInt(Request.QueryString["cid"]);
        if (nCountry == 0)
            nCountry = 1;

        return nCountry;
    }

    private void LoadData()
    {
        try
        {
            int nItemID = ConvertData.ConvertToInt(Request.QueryString[Config.TOUR_ID]);
            if (nItemID > 0)
            {
                GetDataToArrDest(nItemID);
                GetData(nItemID);

            }
        }
        catch
        {
            Response.Redirect("Default.aspx");
        }
    }
    private void SetLangLable()
    {
        //   lblBookTour.Text = MultipleLanguage.LBL_BookTour[nCurrentLang - 1];
        lblDestination.Text = MultipleLanguage.TOURDESTINATION[nCurrentLang - 1];
        //   lblRelatedTours.Text = MultipleLanguage.RELATEDTOUR[nCurrentLang - 1];
        lblOverview.Text = MultipleLanguage.LBL_TOUROVERVIEW[nCurrentLang - 1];
        lblPrice.Text = MultipleLanguage.PRICE[nCurrentLang - 1];
        //lblTripHighlight.Text = MultipleLanguage.TRIPHIGHLIGHT[nCurrentLang - 1];
        lblPhotos.Text = MultipleLanguage.PHOTO[nCurrentLang - 1];
        lblVideo.Text = MultipleLanguage.TOURVIDEO[nCurrentLang - 1];
    }

    private void GetData(int nTourID)
    {
        Tours objTour = new Tours();
        objTour.LoadById(nTourID);
        BindDataToRptRelatedTour(nTourID, ConvertData.ConvertToString(objTour.Data.TourCategoryID));

        Tours objTous = new Tours();
        objTous.LoadById(nTourID);

        SaleOff objSaleOff = new SaleOff();
        if (objTous.Data.SaleOffID > 0)
        {
            objSaleOff.LoadById(objTous.Data.SaleOffID);
        }
        TourDestination objStartTourDest = new TourDestination();
        if (objTous.Data.StartDestinationID > 0)
        {
            objStartTourDest.LoadById(objTous.Data.StartDestinationID);
        }
        TourDestination objArrivedTourDest = new TourDestination();
        if (objTous.Data.StartDestinationID > 0)
        {
            objArrivedTourDest.LoadById(objTous.Data.ArrivedDestinationID);
        }
        lnkBook.NavigateUrl = "~/TourBooking.aspx?cid=" + GetCountryID();

        
        //if (objTous.Data.Image != "")
        //    imgImage.ImageUrl = Config.ROOT + Config.IMAGE_TOUR_UPLOAD + objTous.Data.Image.ToString();
        //else imgImage.ImageUrl = Config.ROOT + "/Images/no_image.gif";

        switch (nCurrentLang)
        {
            case 1:
              //  lblInitContent.Text = objTous.Data.InitContent1;
                lblTitle.Text = objTous.Data.Title1;
                lblDuration.Text = this.GetTourDuration(objTous.Data.TourDurationID);
                ltrContent.Text = objTous.Data.Content1;
          //      lblValTitle.Text = objTous.Data.Title1;
                ltrPrice.Text =   objTous.Data.Price1;
               ltrTripHighlight.Text = objTous.Data.TripHighlight1;
              


                break;
            case 2:
            //    lblInitContent.Text = objTous.Data.InitContent2;
                lblTitle.Text = objTous.Data.Title2;
                lblDuration.Text = this.GetTourDuration(objTous.Data.TourDurationID);
                ltrContent.Text = objTous.Data.Content2;
           //     lblValTitle.Text = objTous.Data.Title2;
                 ltrPrice.Text =   objTous.Data.Price2;
               ltrTripHighlight.Text = objTous.Data.TripHighlight2;
              
                break;
            case 3:
               // lblInitContent.Text = objTous.Data.InitContent3;
                lblTitle.Text = objTous.Data.Title3;
                lblDuration.Text = this.GetTourDuration(objTous.Data.TourDurationID);
                ltrContent.Text = objTous.Data.Content3;
           //     lblValTitle.Text = objTous.Data.Title3;
                 ltrPrice.Text =   objTous.Data.Price3;
                ltrTripHighlight.Text = objTous.Data.TripHighlight3;
              
                break;
        }
        DataTable dtbTour = new DataTable();
        TourImage objImage = new TourImage();
        int nPageCount = 0;
        dtbTour = objImage.Search(nTourID, 1, 100, ref nPageCount);
        rptGallery.DataSource = dtbTour;
        rptGallery.DataBind();

    }

    private string GetTourDuration(int nID)
    {
        string sReturn = ""; 
        TourDuration objTourDuration = new TourDuration();
        objTourDuration.LoadById(nID);
        switch (nCurrentLang)
        { case 1:
                sReturn = "(" + objTourDuration.Data.DurationDescription1 + ")";
                break;
            case 2:
                sReturn = "(" + objTourDuration.Data.DurationDescription2 + ")";
                break;
            case 3:
                sReturn = "(" + objTourDuration.Data.DurationDescription3 + ")";
                break;
        }
        
        return sReturn;
    }
    private void GetDataToArrDest(int TourID)
    {
        ArrivedDestination objArrivedDes = new ArrivedDestination();
        DataTable dtbArrivedDes = objArrivedDes.Search(TourID);
        rpt_TourDestination.DataSource = dtbArrivedDes;
        rpt_TourDestination.DataBind();
    }
    protected void rptTour_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
    }
    protected void rpt_TourDestination_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);

        switch (strCommand)
        {
            case "image":
                string sDetail = Config.ROOT + Pages.FrontEnds.TOURDEST_DETAIL + "?" + Config.TOUR_DES + "=" + nID;
                Response.Redirect(sDetail);
                break;
        }
    }
    protected void rpt_TourDestination_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkTourDestination = (HyperLink)e.Item.FindControl("lnkTourDestination");
            Literal ltrTourDest = (Literal)e.Item.FindControl("ltrTourDest");

            ImageButton imgImageDesTour = (ImageButton)e.Item.FindControl("imgImageDesTour");
            if (ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image")) != "")
                imgImageDesTour.ImageUrl = Config.ROOT + Config.IMAGE_TOURDESTINATION_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            else imgImageDesTour.ImageUrl = Config.ROOT + "/Images/no_image.gif";
            imgImageDesTour.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourDestinationID"));
            lnkTourDestination.NavigateUrl = Config.ROOT + Pages.FrontEnds.TOURDEST_DETAIL + "?" + Config.TOUR_DES + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourDestinationID")) + "&cid=" + GetCountryID();
          
          

            switch (nCurrentLang)
            {
                case 1:
                    lnkTourDestination.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourDestinationTitle1"));
                    ltrTourDest.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent1"));
                    break;
                case 2:
                    lnkTourDestination.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourDestinationTitle2"));
                    ltrTourDest.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent2"));
                    break;
                case 3:
                    lnkTourDestination.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourDestinationTitle3"));
                    ltrTourDest.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent3"));
                    break;
            }
        }

    }
    private void BindDataToRptRelatedTour(int nTourID, string nTourCat)
    {
        Tours objTour = new Tours();
        DataTable dtbTour = new DataTable();
        int nPageCount = 0;
        int nPageSize = 20;

        dtbTour = objTour.Search(10, nTourID, "", 0, 0, 0, 0, 0, 0, nTourCat, nDefaultLang, Support.GetCurrentLanguage(), -1, 1, 1, nPageSize, ref nPageCount);
    //    rptRelatedTour.DataSource = dtbTour;
   //     rptRelatedTour.DataBind();
    }

    protected void rpt_RelatedTour_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkRelatedTour = (HyperLink)e.Item.FindControl("lnkRelatedTour");
            lnkRelatedTour.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title"));
            lnkRelatedTour.NavigateUrl = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "="
                + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID"));
        }
    }
    protected void rptGallery_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Image imgImage = (Image)e.Item.FindControl("imgImage");
            imgImage.ImageUrl = Config.ROOT + Config.IMAGE_TOUR_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Filename"));
        }
    }
}